<!--

eva.construct = function()
{
	$("a[rel=external]").attr("target", "_blank");
	//handler elements display
	jQuery(".tobe_show").show();
	jQuery(".tobe_hide").hide();

	eva.ui.init();

	$(".search_field").each(function(){
		$(this).addClass('ui-widget ui-widget-content ui-corner-all');//.wrapInner('<div class="" />');
		$(" legend" ,this).addClass("ui-widget-title ui-state-default");
	});
}

eva.checkCurrent = function(accordion){
	var router = eva.getRouterName() + ';';
	var index = ($(accordion).find("[data-check*='" + router + "']").addClass('current').parent().index() - 1) / 2;
	$(accordion).accordion("activate", index);
}

eva.reorder = function(name){

	$("#reorder_form").submit(function(){

		var ids = [];
		var order = [];

		$('input[name=' + name + '[]]').each(function(){
			ids.push($(this).val());
		});

		$('input[name=orderNumber[]]').each(function(){
			order.push($(this).val());
		});

		if(ids.length != order.length)
			return alert('Re-order error');

		$("input[name=id_string]").val(ids.join(","));		
		$("input[name=order_string]").val(order.join(","));		

	});

};

eva.quickedit = function(){
	$('.quick_edit').css('visibility','hidden').parent().hover(function (){
		$('.quick_edit',this).css({"visibility":"visible"});
	},function(){
		$('.quick_edit',this).css({"visibility":"hidden"});
	});				
}

eva.module.Admin_indexPosts = function(){
	eva.reorder('post_id');
	eva.batchoperations('post');
}

eva.module.Admin_indexComments = function(){
	eva.batchoperations('comment');
}

eva.module.Admin_getComments = function(){
	eva.batchoperations('comment');
}

eva.module.Admin_getPosts = function(){
	var switchTemplate = function(usage){
		var column = $(".templates").parent();
		column.hide();
		if(usage == 'page'){
			column.show();
		}
	}
	$("select[name=postUsage]").change(function(){
		switchTemplate($(this).val());
	});

	switchTemplate($("select[name=postUsage]").val());

	$(" .templates li").click(function(){
		if(!confirm("For changing template, all content in editor will be clear, are you sure?"))
			return;
		eva.editor.template($(this).attr("className"));
	})
}

eva.getPostsPostnew = function(){
	eva.module.Admin_getPosts();			   
}


eva.postPosts = function(){
	eva.module.Admin_getPosts();			   
}

eva.putPosts = function(){
	eva.module.Admin_getPosts();			   
}


eva.getAdminUploadimages = function(){
	if(!$('#' + $.upload.config.button_placeholder_id)[0])
		return;

	$('#' + $.upload.config.button_placeholder_id).empty();

	var url = '/images.js';

	$.upload.init({
		upload_url: eva.d(url),
		flash_url : eva.s("/javascripts/swfupload.swf")
	},{
		barImage: eva.s('/skins/admin/progressbg_black.gif'),
		boxImage : eva.s('/skins/admin/progressbar.gif')
	});

	$("#category").change(function(){
		var upload_url = eva.d(url + $(this).val());
		$.upload.swfuIntance.setUploadURL(upload_url);
	});
	
	$("#startUpload").click(function(){
		$.upload.swfuIntance.startUpload();
		if($("#production_id").val()){
			var upload_url = eva.d(url + '?production_id=' + $('#production_id').val());
			$.upload.swfuIntance.setUploadURL(upload_url);
		} else {
			var upload_url = eva.d(url + '?game_id=' + $('#game_id').val());
			$.upload.swfuIntance.setUploadURL(upload_url);

		}
		return false;
	});
}

eva.resource = {

	checkResource : function(item){
		var checked = $(item).attr("checked");
		var content = $(item).parent().parent();
		if(checked == 'checked') {
			$(" .operate input",content).attr("checked","checked");
			$(" .operate",content).slideDown();
		} else {
			$(" .operate input",content).attr("checked","");
			$(" .operate",content).slideUp();
		}
	},

	init : function(){

		$(".resource input[name='resource_id[]']").each(function(){

			$(this).attr("onclick","eva.resource.checkResource(this);");

			if(!$(this).attr("checked")) {
				var content = $(this).parent().parent();
				$(" .operate",content).hide();
			}

		});

		
	}
	
}

eva.module.Admin_indexRoles = function()
{
	eva.resource.init();

}

eva.module.Admin_getRoles = function()
{
	eva.module.Admin_indexRoles();
}

eva.production = {

	size : ['small','medium','large'],
	/*{
		small : false,
		medium: false,
		large : false
	},*/

	count : 0,

	maxItem : 3,

	setUnique : function(item){

		if(this.checkMax() === false){
			return $("#add_item").attr("disabled","disabled");
		}
		
		return $("#add_item").attr("disabled","");

		/*
		function remove(item,arr){
			var newArr = [];
			for(var i in arr){
				if(arr[i] == item){
					continue;
				}
				newArr.push(arr[i]);
			}

			return newArr;
		}

		var first = $("fieldset:first");
		var firstSize = $(" select[name='productionSize']",first).val();
		var size = this.size;


		//when change select
		if(item){
		
		} else {
			size = remove(firstSize,size);
			//when copy
			var second = $("fieldset:eq(1)");
			if(second[0]){
				var secondSize = $(" select[name='Subproductions[productionSize][]']",second).val();
				size[secondSize] = true;
			
			}		
		
		}
		*/


	},

	checkMax : function(){
		if($("fieldset").length >= this.maxItem){
			return false;
		}

		return true;
	},
	
	init : function(){
		
		this.initItem("fieldset:first");
		if($("fieldset").length > 1){
			var i = 0;
			$("fieldset").each(function(){
				if(i == 0)
					return i++;

				eva.production.initItem(this,true)
				i++;			
			})
		}

		$(window).load(function(){
			eva.production.cutting();
		});

		$("#add_item").attr("onClick","eva.production.copy()");
	},

	initItem : function(selector,newItem){
		var item = 	$(selector);
		var name = 'productionSize';
		if(newItem){
			name = 'Subproductions[' + name + '][]';
			$(' legend',item).append('<span class="remove" onClick="eva.production.remove(this);">remove</span>');
		}

		item.each(function(){
			var size = $(" select[name='" + name + "']",this).find("option:selected").text();
			$(' legend .size',this).html(size);
		});	

		$(" select[name='" + name + "']",item).attr('onChange','eva.production.changeSize(this)');
	},

	newItem : function(item,newId){
		if($(item).attr('id'))
			$(item).attr('id',$(item).attr('id') + newId);
		
		if($(item).attr('for'))
			$(item).attr('for',$(item).attr('for') + newId);

		if($(item).attr('name')) {
			var name = $(item).attr('name');
			var newName = 'Subproductions[' + name + '][]';
			var value = $("fieldset:first *[name='" + name + "']").val();
			$(item).val(value);
			$(item).attr('name',newName);		
		}

	},

	//item is select box
	changeSize : function(item){
		var fieldset = $(item).parentsUntil('fieldset').parent();
		$(' legend .size',fieldset).html($(item).val());
	},

	copy : function(){
		if(this.checkMax() === false){
			return;
		}

		var id = 'fieldset_' + this.count;
		var newId = '_' + this.count;
		var html = $("fieldset:first").html();
		var className = $("fieldset:first").attr('className');
		$(".main").append('<fieldset id="' + id + '" class="' + className + '">' + html + '</fieldset>');

		var newField = $("#" + id);
		$(' input, label , select , textarea',newField).each(function(){
			eva.production.newItem(this,newId);
		});

		this.initItem("#" + id,true);

		this.count++;

		this.setUnique();
	},

	cutting : function(){
		var url_back = $(".thumbnail_tmp").attr("src");
		$("#thumbnail_cut").css({"visibility":"hidden"});

		$("#show_setting").click(function(){
			$("#thumbnail_cut").css({"visibility":"visible"});

			$.modal($("#thumbnail_cut"), {
				closeHTML:"<a href='#' class='modalCloseImg'>Close</a>",
				containerCss:{
					background:"#333",
					border:"3px solid #444",
					padding:"10px",
					'font-size':"1.2em",
					color:"#FFF",
					padding:0
				},
				onClose : function(){
					preview();
					$("#save_thumbnail").val(1);
					$.modal.close();
					$("#thumbnail_cut").css({"visibility":"hidden"});
				},
				overlayClose:true
			});


			var width = $("#thumbnail").width();
			var height = $("#thumbnail").height();

			$("#simplemodal-container").width(width + 250);
			$("#simplemodal-container").height(height + 30);

			var backup = [];
			$(".thumbnail_selection").each(function(){
				backup.push($(this).val())	
			});
			var backup_click = $("#save_thumbnail").val();

			$("input[name='thumbnail[x1]']").val(0);
			$("input[name='thumbnail[y1]']").val(0);
			$("input[name='thumbnail[x2]']").val(width);
			$("input[name='thumbnail[y2]']").val(width);

			$("#thumbnail").css({
				"float":"left",
				"margin":"20px"
			});
			$("#thumbnail").imgAreaSelect({
				aspectRatio: '1:0.8',
				x1: 0,
				y1: 0,
				x2: height * 0.5 / 0.8,
				y2: height * 0.5,
				parent: '#thumbnail_cut',
				onSelectEnd: function (img, selection) {
					for(var i in selection) {
						$("input[name='thumbnail[" + i + "]']").val(selection[i]);
					}
					preview();
				}
			});

			var click = 0;
			var version = Date.parse(new Date()) + "_" + click;

			var preview = function(){
				var cut = [];
				$(".thumbnail_selection").each(function(){
					cut.push($(this).val())	
				});
				$.getJSON(eva.d('/images/cut/' + eva.config.params.production + '.js' + '?weight=' + cut.join("_")),function(data) {
					if(data.success) {

						$(".thumbnail_tmp").attr("src","/tmp/" + eva.config.params.production + ".jpg?version=" + version);
					
					} else if (data.error) {
					
						alert(data.error);
					
					}

					click++;

					version = Date.parse(new Date()) + "_" + click;
				});
			}
				
		});

		$("#reset_setting").click(function(){
			$(".thumbnail_tmp").attr("src",url_back);
			$("#save_thumbnail").val(0);
			return false;
		});				  
	},

	//item is legend span
	remove : function(item){
		$(item).parent().parent().remove();
		this.setUnique();
	}
}

eva.batchoperations = function(name)
{
	//checkbox
	var checked = false;
	$("#checkall").click(function(){
		$("input[class='checkall']").attr("checked",!checked);
		checked = !checked;
	});

	//grid submit
	$(".page_action .btn").each(function(){
		$(this).click(function(){
			var isChecked = false;
			$("input[class='checkall']").each(function(){
				if($(this).prop("checked") == true) {
					isChecked = true;
					return;
				}
			});
				
			if(isChecked === false)
				return;
				
			var value = $(" span",this).html();

			value = eva.selectThis("#pageAction",value);

			$(".checkall:checked").each(function(){
				$(".batch").append('<input name="' + name + '_ids[]" type="hidden" value="' + $(this).val() + '" />');	
			});
			
			$(".promokeys:checked").each(function(){
				$(".batch").append('<input name="promos[]" type="hidden" value="' + $(this).val() + '" />');	
			});
			
			$(".servicekeys:checked").each(function(){
				$(".batch").append('<input name="services[]" type="hidden" value="' + $(this).val() + '" />');
			});
			
			storeKey = $("#select_storeKey").val();

			if (storeKey) {	
				$(".batch").append('<input name="selectstorekey" type="hidden" value="' + storeKey + '" />');
			}
			
			if(value == 'delete') {
				if(confirm("Selected " + name + " will be delete,are you sure?"))
					$(".batch").submit();
			} else {
				$(".batch").submit();
			}
		});
	});

}

eva.selectThis = function(selector,text){
	var sel = $(selector);
	var val;

	$(" option",sel).each(function(){
        if($(this).text() == text)
        {
			val = $(this).val();
			return sel.prop("value",val);
			
        }		
	});

	return val;
}



eva.module.Admin_indexProducts = function()
{
	eva.batchoperations('product');

	function resultForm(){
		var priceform = $(".result_form");

		var maxRetry = 4;

		var retry = 0;

		var success = function(response){
			if(!response.data) {
				return;
			}

			if(response.data.productTitle) {
				$("#price_process").after('<p>' + response.data.productTitle + '  -  (' + response.data.storeTitle + ') - (' + response.data.process + '/' + response.data.productCount + ')</p>');
			}

			$.ajax({
					'url': eva.d('/backend/updateprices.js'),
					'dataType' : 'json',
					'data' : response.data,
					success: success
					});
		}

		var options = { 
		  success:  success,  // post-submit callback 
		  url:      eva.d('/backend/updateprices.js'),
		  dataType: 'json'
		}; 

		priceform.ajaxForm(options); 
	}

	resultForm();
	
	function matchAllForm(){
		var priceform = $(".matchall_form");

		var maxRetry = 4;

		var retry = 0;
		
		var success = function(response){
			if(!response.data) {
				return;
			}
			
			$("#match_data").val(JSON.stringify(response.data));
			
			if(response.data.productTitle) {
				$("#match_process").after('<p>' + response.data.productTitle + '  -  (' + response.data.storeTitle + ') - (' + response.data.process + '/' + response.data.count + ')</p>');
			}
			
			if (!response.data.queueCount) {
				return;
			}
			
			if (response.data.count == response.data.process) {
				return;
			}
			
			$.ajax({
					'url': eva.d('/match.js'),
					'dataType' : 'json',
					'data' : response.data,
					success: success
					});
		}

		var options = { 
		  success:  success,  // post-submit callback 
		  url:      eva.d('/match.js'),
		  dataType: 'json'
		}; 

		priceform.ajaxForm(options); 
	}

	matchAllForm();
	
	function matchForm(){
		var priceform = $(".match_form");

		var maxRetry = 4;

		var retry = 0;

		var success = function(response){
			if(!response.data) {
				return;
			}
			
			if (!response.data.productId) {
				return;
			}

			if (response.data.count == response.data.process) {
				alert('匹配成功！');
				return;
			}

			$.ajax({
					'url': eva.d('/match/product.js'),
					'dataType' : 'json',
					'data' : response.data,
					success: success
					});
		}

		var options = { 
		  success:  success,  // post-submit callback 
		  url:      eva.d('/match/product.js'),
		  dataType: 'json'
		}; 

		priceform.ajaxForm(options); 
	}

	matchForm();
	
	var form = $(".price_form");

	var maxRetry = 4;

	var retry = 0;

	var success = function(response){
		if(!response.data) {
			return;
		}

		if (response.data.productCount == response.data.process) {
			alert('更新成功！');
		}

		$.ajax({
				'url': eva.d('/backend/updateprice.js'),
				'dataType' : 'json',
				'data' : response.data,
				success: success
				});
	}

	var options = { 
          success:  success,  // post-submit callback 
		  url:      eva.d('/backend/updateprice.js'),
		  dataType: 'json'
	}; 

	form.ajaxForm(options);
}
eva.getProducts = function()
{
	$('.column').hide();
	$('#general').show();
	$("#tab_menu li a").click(function(){
		$("#tab_menu li").removeClass('current');
		$(this).parent().addClass('current');
		var id = $(this).attr('href').toLowerCase();
		$('.column').hide();
		if(id == '#images'){
			$(".production_submit").hide();
		}else {
			$(".production_submit").show();
		}
		$(id).show();
	});

	var form = $(".price_form");

	var maxRetry = 4;

	var retry = 0;

	var success = function(response){
		if(!response.data) {
			return;
		}

		if (response.data.productCount == response.data.process) {
			alert('更新成功！');
		}

		$.ajax({
				'url': eva.d('/backend/updateprice.js'),
				'dataType' : 'json',
				'data' : response.data,
				success: success
				});
	}

	var options = { 
		  success:  success,  // post-submit callback 
		  url:      eva.d('/backend/updateprice.js'),
		  dataType: 'json'
	}; 

	form.ajaxForm(options);

	function matchForm(){
		var priceform = $(".match_form");

		var maxRetry = 4;

		var retry = 0;

		var success = function(response){
			if(!response.data) {
				return;
			}
			
			if (!response.data.productId) {
				return;
			}

			if (response.data.count - 1 == response.data.process) {
				alert('匹配成功！');
				return;
			}

			$.ajax({
					'url': eva.d('/match/product.js'),
					'dataType' : 'json',
					'data' : response.data,
					success: success
					});
		}

		var options = { 
		  success:  success,  // post-submit callback 
		  url:      eva.d('/match/product.js'),
		  dataType: 'json'
		}; 

		priceform.ajaxForm(options); 
	}

	matchForm();
}

eva.getProductsImportnew = function(){
	var form = $(".importnew_form");

	var maxRetry = 4;

	var retry = 0;

	var success = function(response){
		if(!response.data) {
			return;
		}

		$("#importnew_data").val(JSON.stringify(response.data));

		if(response.data.departmentTitle && !response.data.productTitle) {
			$("#importnew_process").after('<p>' + response.data.departmentTitle + '  -  ' + response.data.page + '</p>');
		}

		if(response.data.productTitle) {
			$("#importnew_process").after('<p>' + response.data.productTitle + '  -  (' + response.data.process + '/' +  (response.data.productCount - 1) + ')</p>');
		}

		$.ajax({
				'url': eva.d('/backend/importnew.js'),
				'dataType' : 'json',
				'data' : response.data,
				success: success
				});
	}

	var options = { 
		  success:  success,  // post-submit callback 
		  url:      eva.d('/backend/importnew.js'),
		  dataType: 'json'
	}; 

	form.ajaxForm(options);
}

eva.getProductsMatchnew = function(){
	var form = $(".matchnew_form");

	var maxRetry = 4;

	var retry = 0;

	var success = function(response){
		
		if(!response.data) {
			return;
		}
		
		$("#matchnew_data").val(JSON.stringify(response.data));

		if(!response.data.matchStart) {
			$("#matchnew_process").after('<p>' + response.data.total + '  -  ' + response.data.s *  response.data.rows + '</p>');
		}

		if(response.data.productTitle) {
			$("#matchnew_process").after('<p>' + response.data.productTitle + '  -  (' + response.data.process + '/' +  (response.data.queueCount - 1) + ')</p>');
		}

		$.ajax({
				'url': eva.d('/backend/matchnew.js'),
				'dataType' : 'json',
				'data' : response.data,
				success: success
				});
	}

	var options = { 
		  success:  success,  // post-submit callback 
		  url:      eva.d('/backend/matchnew.js'),
		  dataType: 'json'
	}; 

	form.ajaxForm(options);
}

eva.getAdminGame = function()
{
	eva.getAdminProductionnew();

	$('.show_ajax_form').click(function() {

			$(".ajax_form:visible").each(function() {
				var id = $(this).attr('id');

				$(this).css({
					'position' : 'absolute',
					'top' : 'auto',
					'left' : 'auto'
					});

				$("a[href='#" + id + "']").parent().css({'margin-bottom' : 0});
				}).hide();

			var p = $(this).position();	

			var form = $(this).attr('href');

			$(form).css({
				'position' : 'absolute',
				'top' : p.top + $(form).height() - 10,
				'left' : p.left
				}).show();

			$(this).parent().css({
					'margin-bottom'	: $(form).height() + 20
					});

			return false;
	});

	$('#company_ajax_form').submit(function() {
			var options = { 
success:       showResponse  // post-submit callback 
}; 	

$('#company_ajax_form').ajaxSubmit(options);

		function showResponse(json)  { 
    		$('#game_publisher option:selected').attr('selected',null);
			var json = JSON.parse(json);
    		
			if(json.errors){
				alert('An error has occurred');
				return;
			}else if(json.valids){
				alert('valid failed');
				return;
			}
			
			$('#game_publisher').append('<option selected="selected" value="' + json.data.value + '">' + json.data.name + '</option>');
    		$('#game_developer').append('<option value="' + json.data.value + '">' + json.data.name + '</option>');
			$("#company_ajax_form input[name='title']").val(null);
		
			$("a[href='#company_ajax_form']").click();
		}
		return false;
	});

	$('#genre_ajax_form').submit(function() {
		var options = { 
        	success:       showResponse  // post-submit callback 
    	}; 	

		$('#genre_ajax_form').ajaxSubmit(options);
	
		function showResponse(json)  { 
    		$('#game_genre option:selected').attr('selected',null);
			var json = JSON.parse(json);
    		
			if(json.errors){
				alert('An error has occurred');
				return;
			}else if(json.valids){
				alert('valid failed');
				return;
			}
			
			$('#game_genre').append('<option selected="selected" value="' + json.data.value + '">' + json.data.name + '</option>');
			$("#genre_ajax_form input[name='title']").val(null);
			
			$("a[href='#genre_ajax_form']").click();
		}
		return false;
	});

	$('#platform_ajax_form').submit(function() {
		var options = { 
        	success:       showResponse  // post-submit callback 
    	}; 	

		$('#platform_ajax_form').ajaxSubmit(options);
	
		function showResponse(json)  { 
    		$('#game_platform option:selected').attr('selected',null);
			var json = JSON.parse(json);
    		
			if(json.errors){
				alert('An error has occurred');
				return;
			}else if(json.valids){
				alert('valid failed');
				return;
			}
			
			$('#game_platform').append('<option selected="selected" value="' + json.data.value + '">' + json.data.name + '</option>');
			$("#platform_ajax_form input[name='title']").val(null);
			
			$("a[href='#platform_ajax_form']").click();
		}
		return false;
	});

	$('#credit_ajax_form').submit(function() {
		var options = { 
        	success:       showResponse  // post-submit callback 
    	}; 	

		$('#credit_ajax_form').ajaxSubmit(options);
	
		function showResponse(json)  { 
			var json = JSON.parse(json);
    		
			if(json.errors){
				alert('An error has occurred');
				return;
			}else if(json.valids){
				alert('valid failed');
				return;
			}
			$('#game_credit').prepend('<li><label><input type="checkbox" checked="checked" value="' + json.data.value + '" name="Gamecredits[]"> ' + json.data.name + '</label></li>');
			$("#credit_ajax_form input[name='producerName']").val(null);
			
			$("a[href='#credit_ajax_form']").click();	
		}
		
		return false;
	});

	$('#tag_ajax_form').submit(function() {
		var options = { 
        	success:       showResponse  // post-submit callback 
    	}; 	

		$('#tag_ajax_form').ajaxSubmit(options);
	
		function showResponse(json)  { 
			var json = JSON.parse(json);
    		
			if(json.errors){
				alert('An error has occurred');
				return;
			}else if(json.valids){
				alert('valid failed');
				return;
			}
			$('#game_tag').prepend('<li><label><input type="checkbox" checked="checked" value="' + json.data.value + '" name="Tags[]"> ' + json.data.name + '</label></li>');
			$("#tag_ajax_form input[name='tagName']").val(null);
			
			$("a[href='#tag_ajax_form']").click();	
		}
		
		return false;
	});
}

eva.getDepartments = function(){
	eva.reorder('department_id');
	
	function importForm(){
		var form = $(".import_form");

		var maxRetry = 4;

		var retry = 0;

		var success = function(response){
			if(!response.data) {
				return;
			}
			
			$("#import_data").val(JSON.stringify(response.data));

			if(response.data.departmentTitle && !response.data.productTitle) {
				$(".process").after('<p>' + response.data.departmentTitle + '  -  ' + response.data.page + '</p>');
			}

			if(response.data.productTitle) {
				$(".process").after('<p>' + response.data.productTitle + '  -  (' + response.data.process + '/' +  (response.data.productCount - 1) + ')</p>');
			}

			$.ajax({
					'url': eva.d('/backend/import.js'),
					'dataType' : 'json',
					'data' : response.data,
					success: success
					});
		}

		var options = { 
		  success:  success,  // post-submit callback 
		  url:      eva.d('/backend/import.js'),
		  dataType: 'json'
		}; 

		form.ajaxForm(options);
	}
	importForm();

	var priceform = $(".price_form");

	var maxRetry = 4;

	var retry = 0;

	var success = function(response){
		if(!response.data) {
			return;
		}

		if(response.data.productTitle) {
			$(".price_process").after('<p>' + response.data.productTitle + '  -  (' + response.data.storeTitle + ') - (' + response.data.process + '/' + response.data.productCount + ')</p>');
		}

		$.ajax({
				'url': eva.d('/backend/updateprices.js'),
				'dataType' : 'json',
				'data' : response.data,
				success: success
				});
	}

    var options = { 
        success:  success,  // post-submit callback 
        url:      eva.d('/backend/updateprices.js'),
        dataType: 'json'
    }; 
 
    priceform.ajaxForm(options); 
}

eva.getToolUpdateprices = function(){

	var priceform = $(".price_form");

	var maxRetry = 4;

	var retry = 0;

	var success = function(response){
		if(!response.data) {
			return;
		}

		if(response.data.productTitle) {
			$("#price_process_" + response.data.departmentId).after('<p>' + response.data.productTitle + '  -  (' + response.data.storeTitle + ') - (' + response.data.process + '/' + response.data.productCount + ')</p>');
		}

		$.ajax({
				'url': eva.d('/backend/updateprices.js'),
				'dataType' : 'json',
				'data' : response.data,
				success: success
				});
	}

    var options = { 
        success:  success,  // post-submit callback 
        url:      eva.d('/backend/updateprices.js'),
        dataType: 'json'
    }; 
 
    priceform.ajaxForm(options); 
}

eva.getToolAlerts = function(){
	
	var form = $(".alerts_form");

	var maxRetry = 4;

	var retry = 0;
	


	var success = function(response){
		if(!response.data) {
			return;
		}
		
		$("#alert_submit").attr('disabled', 'disabled');
		
		if(response.data.count && response.data.page) {
			$(".process").after('<p>' + response.data.page + '/' +  response.data.count + '</p>');
			
			if (response.data.page == response.data.count) {
				$(".process").after('<p>全部生成！</p>');
				$("#alert_submit").removeAttr('disabled');
			}
		}

		$.ajax({
			'url': eva.d('/backend/createmail.js'),
			'dataType' : 'json',
			'data' : response.data,
			success: success
		});
	}

	var options = { 
		success:  success,  // post-submit callback 
		url:      eva.d('/backend/createmail.js'),
		dataType: 'json'
	}; 

	form.ajaxForm(options);
}

eva.getToolSendemails = function(){
	
	var form = $(".sendemails_form");

	var maxRetry = 4;

	var retry = 0;

	var success = function(response){
		if(!response.data) {
			return;
		}

		if(response.data.count && response.data.process) {
			$(".process").after('<p>' + response.data.email + ' (' + (response.data.process - 1) + '/' +  response.data.count + ')</p>');
		}

		$.ajax({
			'url': eva.d('/backend/sendmail.js'),
			'dataType' : 'json',
			'data' : response.data,
			success: success
		});
	}

	var options = { 
		success:  success,  // post-submit callback 
		url:      eva.d('/backend/sendmail.js'),
		dataType: 'json'
	}; 

	form.ajaxForm(options);
}

eva.getToolInsertpricelogs = function(){

	var priceform = $(".price_form");

	var maxRetry = 4;

	var retry = 0;

	var success = function(response){
		if(!response.data) {
			return;
		}

		if(response.data.productTitle) {
			$("#price_process_" + response.data.departmentId).after('<p>' + response.data.productTitle + ' - (' + response.data.process + '/' + response.data.productCount + ')</p>');
		}

		$.ajax({
				'url': eva.d('/tool/pricelogs.js'),
				'dataType' : 'json',
				'data' : response.data,
				success: success
				});
	}

    var options = { 
        success:  success,  // post-submit callback 
        url:      eva.d('/tool/pricelogs.js'),
        dataType: 'json'
    }; 
 
    priceform.ajaxForm(options); 
}

eva.getToolMatchproducts = function(){

	var priceform = $(".price_form");

	var maxRetry = 4;

	var retry = 0;

	var success = function(response){
		if(!response.data) {
			return;
		}

		if(response.data.productTitle) {
			$("#price_process_" + response.data.departmentId).after('<p>' + response.data.productTitle + '  -  (' + response.data.storeTitle + ') - (' + response.data.process + '/' + response.data.count + ')</p>');
		}

		$.ajax({
				'url': eva.d('/match.js'),
				'dataType' : 'json',
				'data' : response.data,
				success: success
				});
	}

    var options = { 
        success:  success,  // post-submit callback 
        url:      eva.d('/match.js'),
        dataType: 'json'
    }; 
 
    priceform.ajaxForm(options); 
}
-->
